package com.i2silly.wxbot.quartz.job;

import com.i2silly.wxbot.quartz.QuartzJobService;
import com.i2silly.wxbot.server.RobotWebsocketServer;
import com.i2silly.wxbot.utils.SpringContextUtil;
import org.java_websocket.enums.ReadyState;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: wx-bot
 * @description：WebSocket重连
 * @author: i2silly
 * @date: 2020年11月24日 15:32:20
 */

@DisallowConcurrentExecution /* @DisallowConcurrentExecution注解等quartz 定时器任务完成后 才会执行后面任务 */
@Component
public class WebsocketReconnJob implements Job {

    Logger logger = LoggerFactory.getLogger(WebsocketReconnJob.class);

    @Autowired
    private RobotWebsocketServer client;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
//        logger.info("webSocket重连监听" + client.getReadyState());
        if (client == null){
            client = new RobotWebsocketServer();
        }
        if (!client.isOpen()) {
            if (client.getReadyState().equals(ReadyState.NOT_YET_CONNECTED)) {
                client.connect();
            } else if (client.getReadyState().equals(ReadyState.CLOSING) || client.getReadyState().equals(ReadyState.CLOSED)) {
                client.reconnect();
            }
        }

        //[BotContact{id='70d174c7d3de4dda8e21cf90817da635', wxid='18577018338@chatroom', name='网关问题', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='6253a957e8614f0fb9a0716dd0dab9dd', wxid='18701419446@chatroom', name='福清云存', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='943bae1500624000950fc3e9d6bd634e', wxid='19324816545@chatroom', name='南威对接海康sdk问题沟通', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='7e51aca6b5b145518e47ba9386db0997', wxid='4943728366@chatroom', name='泉州海康人像多引擎对接', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='76246a4b8af24cadb4bf6f607617cd41', wxid='filehelper', name='文件传输助手', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='41e55902b4ab47e6b866de59e11e87bb', wxid='gh_3dfda90e39d6', name='微信支付', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='3da4f7b15eec4f1eaad9fea70f41da57', wxid='wxid_11piortr757m12', name='东海领地房产中介许聪聪', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='ae1ec967156f4d259dc7e98564ded45a', wxid='wxid_d4xwmj13myut12', name='胖哥', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='9a284f77909846b4a2f43a1f6835fa5c', wxid='wxid_8hwxvcczylry12', name='梦想归谷房东直租（非中介）', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='8e2e779282f74b3dae3ee0b3b04d7d76', wxid='wxid_6bv4uxc8xq8h22', name='🌊', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='1aedb11adab0442393b7b6ceb16623ec', wxid='wxid_1ilouguiybd121', name='AAA房屋租售 尹本杰：18060050923', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='a6d5af4b73674aeda7e24cd761a2e5c3', wxid='wxid_5nflkq2ae47m21', name='老人家', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='11b0e92cb74b47d1baa60048533690ec', wxid='wxid_7zwwt0u614tx21', name='阿琪', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='4cb1ae3ea160413ca0842e32ef415d96', wxid='wxid_9qs1477yza1g22', name='安雅物业-文园管家', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='6d02fb3bec7f497e838161a55e836abf', wxid='wxid_9j639u0jhkkw21', name='彳亍介士', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='c7e65e4875ec40d0904f71998b51fc13', wxid='wxid_ud89haz5jugc22', name='A~泉州租房', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='15a71d26e845474a8b219d6470e82bc0', wxid='wxid_o7w1l300e25d22', name='L。', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='307fda72f85748b88d322e8fc90f94a8', wxid='wxid_lbca2qnlir9h22', name='老张学技术', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='e1352098c7814c0ea736e7f408ae175a', wxid='wxid_ik7j8yg314h222', name='破晓', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='64e02f31917341dc96d44f40d53363cf', wxid='wxid_o6fng5ucpimv22', name='A平安高渐离', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='bf5525ae256845e49a3dcf018753158a', wxid='wxid_qjtaiyy7cud422', name='人土土', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='d937654462f6486a94612aaec13cc247', wxid='xiaoqiang-123321', name='小小蔡', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='a7d78a6d794648828474b1da5d679ff3', wxid='wxid_uw0xm6jo1mwl21', name='Mioory', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='c432778a68b14b4cb3a973487389c974', wxid='z445259714', name='如果有如果', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='1a342ce0ba5e48dc95ffd2d99b6722ec', wxid='z1003680140', name='云间', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='5118f44f2e8a41508b8afdf8625e9759', wxid='medianote', name='语音记事本', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='497e060615e54f4e98afc04c21ad73bc', wxid='gh_483f68d719de', name='福安公安', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='bd3ccb26d7a74a088019562da162be30', wxid='gh_3fc1cecb6f50', name='搜云库技术团队', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='b92db023dbab4fa696c7a7cc3f0cfc6e', wxid='gh_6a9bd97c5642', name='屈臣氏服务助手', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='16b9a334e82e4b859b6520fdde84408f', wxid='gh_662bb61dcc68', name='架构师专栏', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='77d7c2e48ec1434498925a5635169487', wxid='qmessage', name='QQ离线消息', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='dbaeadeecd75485ab75c1d6fe481d024', wxid='newsapp', name='', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='4e96f9eea611453ca6d4f692406abc2a', wxid='muou0360', name='2silly', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='eab30bdc63ba4c6bb934067f36641ef4', wxid='p754129087', name='Pzj', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='d99adab4733c4fd298a9f0895f2679a3', wxid='wuqingshun123', name='顺子', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='8b7572dc3f0c4ae2821090b3b9c9f1fd', wxid='qqmail', name='QQ邮箱提醒', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='18bfe94c8dac49baa47feefb3602fc48', wxid='wxid_0n44ob1n5dfd22', name='🇾 🇦 🇬 🇪 coder', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='09bd001d296241b5a07f7dad49d0091f', wxid='fmessage', name='朋友推荐消息', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='8530732d6d2f4495901df74b575b7924', wxid='floatbottle', name='漂流瓶', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='943836593c8449079d0fbd6e88dbeea6', wxid='gh_25d9ac85a4bc', name='微信游戏', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='e46f8c6d6fdc47258d0478d6c354a3a8', wxid='KangHP', name='咖啡', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='781a96855b9643e9821cffaa7976559d', wxid='Ccccqinyin', name='二狗黒💃', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='d09cd631206a4849a8c6690ec58ecc1e', wxid='WLL5222', name='吴亮亮', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='1eff9175d3b4470f816466ae9e8ce627', wxid='19830316083@chatroom', name='漳浦华为车卡接入南威平台', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='dc8f61c8b07e4388968ec8fb436b9881', wxid='19503019201@chatroom', name='哈哈哈哈', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='13e77fc1b895423a84ebb597f481964b', wxid='19903704971@chatroom', name='福州宇视人像南威对接', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='a99c49d90b194c44b3f00c29d662f255', wxid='22049764763@chatroom', name='老张学技术-PC微信学习群', pid='313058f489614d3790eed67f1dd37781'}, BotContact{id='9fde582e6b8043cf84b724029df55109', wxid='18925120661@chatroom', name='南威&大华前端对接群', pid='313058f489614d3790eed67f1dd37781'}]
    }
}
